package com.caregiver.watch.business.data.utils.time;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Date;
import java.util.TimeZone;

public final class DateTimeUtils {

    public static String convert2DateTimeString(int seconds) {
        Date dt = new Date();
        dt.setTime(seconds * 1000L);
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+:00:00"));
        return sdf.format(dt);
    }

    public static Date convert2DateTime(int seconds) {
        Date dt = new Date();
        dt.setTime(seconds * 1000L);
        return dt;
    }

    public static boolean isValidDate(String dateStr) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        try {
            LocalDate.parse(dateStr, formatter);
            return true;
        } catch (DateTimeParseException e) {
            return false;
        }
    }

    public static String getPreviousDay(String dateStr) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        try {
            LocalDate date = LocalDate.parse(dateStr, formatter);
            LocalDate previousDay = date.minusDays(1);
            return previousDay.format(formatter);
        } catch (DateTimeParseException e) {
            return "";
        }
    }
}
